package com.yycx.module.bus.client.vo;

import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.module.bus.client.entity.BusCustomRate;
import com.yycx.module.bus.client.entity.BusOrder;
import com.yycx.module.bus.client.entity.BusOrderDetails;
import com.yycx.module.bus.client.entity.BusSupplierRate;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单详情计算元素
 *
 * @author zyf
 */
@Data
public class OrderDetailsVo implements Serializable {


    /**
     * 供货方税率配置
     */
    private BusSupplierRate supplierRate;


    /**
     * 购货方税率配置
     */
    private BusCustomRate customRate;

    /**
     * 订单信息
     */
    private BusOrder busOrder;

    /**
     * 订单明细
     */
    private BusOrderDetails busOrderDetails;


    /**
     * 折扣价
     */
    private BigDecimal discountPrice;


    /**
     * 初始化公式计算元素
     *
     * @return
     */
    public Map<String, Object> getVariable() {
        Map<String, Object> variable = new HashMap<>(5);
        BusOrderDetails orderDetails = this.getBusOrderDetails();
        BusSupplierRate supplierRate = this.getSupplierRate();
        BusCustomRate busCustomRate = this.getCustomRate();
        BigDecimal salePrice = orderDetails.getSalePrice();
        BigDecimal costPrice = orderDetails.getCostPrice();
        BigDecimal supplierRetable=FlymeUtils.getBigDecimal(orderDetails.getSupplierRetable(),"0");
        BigDecimal settleAmount=FlymeUtils.getBigDecimal(orderDetails.getSettleAmount(),"0");
        BigDecimal settleAmount2=FlymeUtils.getBigDecimal(orderDetails.getSettleAmount2(),"0");
        BigDecimal settleAmount3=FlymeUtils.getBigDecimal(orderDetails.getSettleAmount3(),"0");
        BigDecimal supplierGapUpPrice = salePrice.subtract(costPrice);
        variable.put("供货方高开价", supplierGapUpPrice);
        variable.put("成本价", costPrice);
        variable.put("票折价", FlymeUtils.getBigDecimal(orderDetails.getDiscountPrice(), "0"));
        if (FlymeUtils.isNotEmpty(discountPrice)) {
            salePrice = discountPrice;
        }
        variable.put("销售单价", salePrice);
        variable.put("数量", orderDetails.getSaleNum());
        variable.put("结算价", orderDetails.getSettlePrice());
        variable.put("成本金额", orderDetails.getCostAmount());
        variable.put("应结金额", settleAmount);
        variable.put("应结金额2", settleAmount2);
        variable.put("应结金额3", settleAmount3);
        variable.put("供方应返", supplierRetable);
        variable.put("销售金额", orderDetails.getSaleAmount());
        variable.put("供货方高开税金", orderDetails.getSupplierGapUpTaxesAmount());
        if (FlymeUtils.isNotEmpty(supplierRate)) {
            variable.put("供货方资保金费率", FlymeUtils.getBigDecimal(orderDetails.getSupplierTaxRate(), supplierRate.getSupplierTaxRate()));
            variable.put("供货方结算费率", FlymeUtils.getBigDecimal(orderDetails.getSupplierSettleRate(), supplierRate.getSupplierSettleRate()));
        }
        if (FlymeUtils.isNotEmpty(busCustomRate)) {
            variable.put("结算高开税金费率", FlymeUtils.getBigDecimal(orderDetails.getCustomSettleGapUpTaxRate(), customRate.getCustomSettleGapUpTaxRate()));
            variable.put("销售结算费率", FlymeUtils.getBigDecimal(orderDetails.getCustomSettleRate(), customRate.getCustomSettleRate()));
            variable.put("保证金费率", FlymeUtils.getBigDecimal(orderDetails.getCustomTaxRate(), customRate.getCustomTaxRate()));
        }
        return variable;
    }


}
